package com.emode.test;

import java.util.HashMap;
import java.util.Map;

public class test {
	/**
	 * 统计每个英文单词的出现的次数
	 * @param args
	 */
	public static void main(String[] args) {
		String text = "Nowadays, if we go on the? street, we can find that fast food is everywhere, the reason why the fast food is so popular lies on that it is convenient. People can finish their meal quickly and spend more time to do work. Fast food indeed saves people a lot of time, but it is not good for our health, we should not eat it often.";
		String[] s = text.replaceAll("\\,|\\.|\\?", "").split(" ");  //过滤字符并转换成数组
		Map<String, Object> map = new HashMap<String, Object>();
		for(int i=0;i<s.length;i++){
			if(map.containsKey(s[i])){  //如果包含
				map.put(s[i], Integer.parseInt(map.get(s[i]).toString())+1);
			}else{  //不包含
				map.put(s[i], 1);
			}
		}
		for(Map.Entry<String, Object> entry:map.entrySet()){
			System.out.println(entry.getKey() +"  :"+entry.getValue());
		}
	}
	
	
}
